package com.neusoft.actor.controller;

import com.neusoft.actor.dto.RoomDto;
import com.neusoft.actor.po.Bed;
import com.neusoft.actor.po.ResponseBean;
import com.neusoft.actor.service.BedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin("*")
@RequestMapping("/BedController")
public class BedController {

    @Autowired
    private BedService bedService;

    @GetMapping("/getAllBeds")
    public ResponseBean<List<Bed>> getAllBeds() {
        return bedService.getAllBeds();
    }

    @GetMapping("/getAllAccessBeds")
//    查询空闲床位
    public ResponseBean<List<Bed>> getAllAccessBeds() {
        return bedService.getAllAccessBeds();
    }

    @GetMapping("/{id}")
    public ResponseBean<Bed> getBedById(@PathVariable Integer id) {
        return bedService.getBedById(id);
    }

    @PostMapping
    public ResponseBean<Integer> addBed(@RequestBody Bed bed) {
        return bedService.addBed(bed);
    }

    @PutMapping("/UpdateBed")
//    更新床位信息
    public ResponseBean<Integer> updateBed(@RequestBody Bed bed) {
        return bedService.updateBed(bed);
    }

    @DeleteMapping("/{id}")
    public ResponseBean<Integer> deleteBed(@PathVariable Integer id) {
        return bedService.deleteBed(id);
    }

    @GetMapping("/getAllRoomsByFloor")
//    查询所有房间
    public ResponseBean<List<RoomDto>> getAllRoomsByFloor() {
        return bedService.getAllRoomsByFloor();
    }

    @GetMapping("/getFreeBedsByRoom")
//    查询房间空床位
    public ResponseBean<List<Bed>> getFreeBedsByRoom(@RequestParam String roomNumber) {
        return bedService.getFreeBedsByRoom(roomNumber);
    }

    @GetMapping("/changeBed")
//    换床位
    public ResponseBean<Integer> changeBed(Integer oldBedId, Integer newBedId, Integer clientId) {
        return bedService.changeBed(oldBedId, newBedId, clientId);
    }

    @GetMapping("/getAllBedsByRoom")
    public ResponseBean<List<Bed>> getAllBedsByRoom(@RequestParam String roomNumber) {
        return bedService.getAllBedsByRoom(roomNumber);
    }

    @GetMapping("/getBedByCon")
//    根据房间号和床号查床位
    public ResponseBean<Bed> getBedByCon(String roomNumber, String bedNumber){
        return bedService.getBedByCon(roomNumber, bedNumber);
    }
}